<template>
    <view class="indexCom">
        <search :gradientScale='gradientScale'></search>
        <scroll @setGradientScale="setGradientScale">
            <banner :list="bannerList" v-if="bannerList.length"></banner>
            <turList :list="turDataList" v-if="turDataList.length"></turList>
            <aylanma :list="yigiList" v-if="yigiList.length"></aylanma>
            <newList :list="newDataList" :title="newDataTitle" v-if="newDataList.length"></newList>
            <homeList :list="homeDataList" v-if="homeDataList.length"></homeList>
        </scroll>
    </view>
</template>

<script>
    import banner from '@/components/index/banner.vue'
    import turList from '@/components/index/turList.vue'
    import aylanma from '@/components/index/aylanma.vue'

    import newList from '@/components/custom/newList.vue'
    import homeList from '@/components/custom/homeList.vue'
    import search from '@/components/custom/search.vue'
    import scroll from '@/components/custom/scrollView.vue'
    import {
        gradientScaleMixin
    } from '@/mixins/gradientScale.js'
    import {
        getHome,
        getHomeIndex,
    } from '@/api/index.js'
    export default {
        components: {
            search,
            scroll,
            banner,
            turList,
            aylanma,
            newList,
            homeList,
        },
        mixins: [gradientScaleMixin],
        data() {
            return {
                bannerList: [],
                turDataList: [],
                yigiList: [],
                newDataList: [],
                newDataTitle: '',
                homeDataList: [],
            }
        },
        mounted() {
            this.getData()
        },
        methods: {
            async getData() {
                this.$emit('setLoading', true)
                const homeRes = await getHome()
                if (!homeRes || (homeRes && homeRes.statusCode != 200)) {
                    return
                }
                this.bannerList = homeRes.data.data.banner
                this.turDataList = homeRes.data.data.turList
                this.yigiList = homeRes.data.data.yigi
                this.newDataList = homeRes.data.data.new
                this.newDataTitle = homeRes.data.data.newTitle


                const homeIndexRes = await getHomeIndex()
                if (!homeIndexRes || (homeIndexRes && homeIndexRes.statusCode != 200)) {
                    return
                }
                this.homeDataList = homeIndexRes.data.data.category

                this.$emit('setLoading', false)
            },
        },
    }
</script>

<style lang="scss" scoped>
    .indexCom {}
</style>